{extend name="Base/common" /}
{block name="content"}
<!-- BEGIN PAGE -->

<div class="page-content" style="padding-top: 10px;">

    <div class="container-fluid">
        <!-- 面包屑开始-->
        <div class="row-fluid">
            <div class="span12">

                <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                <h3 class="page-title">
                    推广码列表
                </h3>
                <ul class="breadcrumb">
                    <li>
                        <a href="/ops/promo/index">列表</a>
                        <i class="icon-angle-right"></i>
                    </li>
                    <li>
                        推广码列表
                    </li>

                </ul>
                <!-- END PAGE TITLE & BREADCRUMB-->
            </div>
        </div>
        <!-- 面包屑结束 -->

        <!-- 带全选的表格开始 -->
        <div class="row-fluid">

            <div class="span12">

                <!-- BEGIN SAMPLE TABLE PORTLET-->

                <div class="portlet">

                    <div class="portlet-title">

                        <div class="caption"><i class="icon-reorder"></i>列表</div>

                        <!-- 表格内容整体操作结束 -->

                    </div>

                    <div class="portlet-body no-more-tables">
                        <button class="layui-btn btn-success" style="margin: 20px 0;" onclick="createPromo()">生成推广码</button>

                        <table class="table-bordered table-striped table-condensed cf" style="text-align: center;">

                            <thead class="cf">

                            <tr>
                                <th>Id</th>

                                <th>推广码</th>

                                <th>小程序码</th>

                                <th>状态</th>

                            </tr>

                            </thead>

                            <tbody>

                            {volist name="list" id="vo"}
                            <tr class="">

                                <td>{$vo.id}</td>

                                <td>{$vo.code}</td>
                                <td>
                                    <img src="{$vo.img}" alt="" style="height: 100px;">
                                </td>
                                <td class="status_{$vo.id}">
                                    {switch name="$vo.status" }
                                    {case value="1"}
                                    <span>可用</span>
                                    {/case}
                                    {case value="0"}
                                    <span style="color: red">不可用</span>
                                    {/case}
                                    {/switch}
                                </td>

                            </tr>
                            {/volist}

                            </tbody>

                        </table>

                    </div>

                </div>
                {$list->render()}
                <!-- END SAMPLE TABLE PORTLET-->

            </div>
        </div>
        <!-- 带全选的表格结束btn-sort-edit -->

    </div>
</div>
<script>
    
    function createPromo() {
        layui.use("layer", function () {
            layer.prompt({
                formType: 0,
                value: '',
                title: '请输入要生成的数量',
                area: '500px',
                offset: ['200px', '45%']
            }, function (value, index, elem) {

                $.post('/ops/promo/add', {num: value}, function (res) {
                    var data = JSON.parse(res);
                    if (data.errno == 0) {

                        layer.close(index);
                        layer.msg('生成成功');
                        location.href = "/ops/promo/index"
                    } else {
                        layer.msg(data.msg, function (e) {

                        })
                    }
                })


            });
        })
    }

    function use_code(id, ob) {
        layui.use("layer", function () {
            $.post('/ops/promo/setstatus', {id: id}, function (res) {
                var data = JSON.parse(res);
                if (data.errno == 0) {
                    layer.msg('操作成功');
                    $(ob).parent().html('-');
                    $(".status_"+id).html("<span>不可用</span>");
                } else {
                    layer.msg(data.msg, function (e) {

                    })
                }
            })

        })
    }
    
</script>
<!-- END PAGE -->
{/block}